package com.health.userbackstage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.health.userbackstage.pojo.Order;
import com.health.userbackstage.pojo.OrderSetting;
import com.health.userbackstage.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * @Author ASUS
 * @Date 2023/8/18 21:18
 * @Version 1.0
 */
public interface OrderSettingMapper extends BaseMapper<OrderSetting> {


    List<OrderSetting> findByDate(String date);
    List<OrderSetting> findByDateRange(@Param("min") String min, @Param("max") String max);
    OrderSetting findOne(String date);

    int increaseReservations(Order order);

    List<Date> getOrderDates();

    void reduceReservations(Order order);

    @Update("UPDATE ordersetting SET reservations = reservations -1 WHERE orderdate  = #{orderDate}")
    int updateReservationsByOrderDate(Date orderDate);

    @Delete("DELETE FROM order_report WHERE order_id = #{orderId}")
    int deleteOrderReportByOrderId(Integer orderId);

    @Select("SELECT o.orderdate FROM `order` o,ordersetting os WHERE  o.`orderdate` = os.`orderdate` AND os.orderdate = #{date}")
    Date selectIdByDate(Date date);
}
